<?php
/**
 * Created by PhpStorm.
 * User: SYSTEM
 * Date: 2018-8-13
 * Time: 14:51
 */

//制作传统分页效果
//连接数据库-》获得数据-》分页显示
header("content-type:text/html;charset=utf-8");
try{

    $pdo = new PDO('mysql:host=localhost; dbname=phptest', 'root', 'root');
    $sql = 'select * from computermenu';

    $stmt = $pdo->query($sql);


    echo <<<eof
        <style type="text/css">
            table{
                width: 700px;
                margin: auto;   
                border: 1px solid black;
                border-collapse: collapse;
            }
            td{
                border: 1px solid black;
            }
        </style>
        <table>
            <tr style="background-color: #e6ffec;">
                <td>序号</td>
                <td>电脑名称</td>
                <td>电脑颜色</td>
                <td>价格</td>
            </tr>
eof;

    $num = 1;
    foreach($stmt as $row){
        echo '<tr>';
        echo '<td>'.$num++.'</td>';
        echo '<td>'.$row['computername'].'</td>';
        echo '<td>'.$row['computercolor'].'</td>';
        echo '<td>'.$row['computerprice'].'</td>';
        echo '</tr>';
    }

    echo '</table>';
}catch(PDOException $e){
    echo $e->getMessage();
}